﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EncuentraloSilverlight.Models;
using System.Runtime.Serialization;

namespace EncuentraloSilverlight.Web.Models
{
    public partial class Product
    {
        public bool IsValid
        {
            get { return (GetProductRuleViolations().Count() == 0); }
        }
        public IEnumerable<RuleViolation> GetProductRuleViolations()
        {
            if (Price <= 0)
                yield return new RuleViolation("Price not valid","Price");
            if (String.IsNullOrEmpty(Name))
                yield return new RuleViolation("Name required", "Name");
            yield break;
        }

    }
}